package com.gujia.concurrent.semaphore;

import com.gujia.concurrent.reentrant.Warehouse;

import java.util.concurrent.Semaphore;

public class WareHouseSemap extends Warehouse{


    private boolean isFull;
    private Semaphore lock = new Semaphore(1);

    public void put(){


        if(isFull){
            try{
                lock.acquire();
                System.out.println("空了，放商品");

                isFull = !isFull;


                lock.release();
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }

    public  void get(){


        if (!isFull){
            try{
             lock.acquire();
                System.out.println("满了，取商品");
                isFull = !isFull;

                lock.release();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }


}
